import com.intGraf.telaPrincipal;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.webserver.WebServer;

public class JavaServer {

    static telaPrincipal janela;
    private String[] leiloes;
    private int i;
    
    //Método de acesso dos clientes que irá reetornar todos os leilões criados até o momento;
    public String[] atualizarLeiloes(){
        
        leiloes = new String[janela.getLeilao().size()];
        
        for(i=0; i<janela.getLeilao().size(); i++){
            if(janela.getLeilao().get(i).getLeilao_ok() == 1)
            {
                leiloes[i] = janela.getLeilao().get(i).getDados();
            }
        }
        
        return leiloes;
    }
    
    //Método importante - DAR LANCE!
    
    
    public Integer sum(int x, int y) {
        return new Integer(x + y);
    }

    public static void main(String[] args) {
        try {
            System.out.println("Attempting to start XML-RPC Server...");
            WebServer server2 = new WebServer(1093);
            
            XmlRpcServer server = server2.getXmlRpcServer();
            
            PropertyHandlerMapping pm = new PropertyHandlerMapping();
            pm.addHandler("sample", (new JavaServer()).getClass());
            server.setHandlerMapping(pm);
            
            server2.start();
            System.out.println("Started successfully.");
            System.out.println("Accepting requests. (Halt program to stop.)");
            
            //criando janela principal.
            janela = new telaPrincipal();
            
        } catch (XmlRpcException | IOException exception) {
            System.err.println("JavaServer: " + exception);
        }
    }
}